/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.bath;

import uk.ac.bath.schemes.BuilderIF;
import uk.ac.bath.environment.Evaluator;
import uk.ac.bath.environment.Fitness;
import uk.ac.bath.environment.MachineIF;
import uk.ac.bath.domains.IP.IPEvaluator;
import uk.ac.bath.domains.IP.IPSetupIF;
import uk.ac.bath.domains.IP.IPSetupQuadVert;

import uk.ac.bath.machines.neuralSane.Neural3Builder;
import uk.ac.bath.machines.neuralSane.VinillaNeural3Builder;

/**
 *
 * @author pjl
 */
public class SimpleMain {

    public static void main(String args[]) {

        // IP specific
        IPSetupIF setup = new IPSetupQuadVert();
        Evaluator eval = new IPEvaluator(setup);

        int nIn = setup.getNIn();
        int nHidden = 8;
        int nOut = setup.getNOut();

        BuilderIF b;
        boolean recursive = true;

        if (false) {
            int nConnect = 5;
            b = new Neural3Builder(nIn, nHidden, nOut, nConnect, recursive);
        } else {
            b = new VinillaNeural3Builder(nIn, nHidden, nOut, recursive);
        }
//        MachineIF mm=b.createRandomMachine();
//
//        MachineIF mmm = b.createMachineFromString(mm.parametersToString());
//        System.out.println(mm.parametersToString());
//        System.out.println(mmm.parametersToString());
//        System.exit(0);
        
//
//        eval.setMachine(m);

        double best = 0.0;

        MachineIF bestMachine = null;

        for (int i = 0; i < 100; i++) {

            MachineIF m = b.createRandomMachine();
            eval.setMachine(m);

            Fitness fit;

            while (!(fit = eval.tick()).decided()) {
                //System.out.println(eval.getStatus() + fit);
            }

            if (fit.fitness > best) {
                best = fit.fitness;
                bestMachine = m;
            }

            System.out.println(m.parametersToString());
            System.out.println(eval.getStatus() + fit);
        }

        MachineIF zzz = b.createMachineFromString(bestMachine.parametersToString());
        eval.setMachine(zzz);

        Fitness fit;
        while (!(fit = eval.tick()).decided()) {
            //System.out.println(eval.getStatus() + fit);
            }
        System.out.println(zzz.parametersToString());
        System.out.println(eval.getStatus() + fit);

    }
}
